import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class test {
    public static void main(String[] args) throws SQLException {

       /* MysqlDataSource mysqlDataSource = new MysqlDataSource();
        DataSource dataSource = new MysqlDataSource();
        //建立连接
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false");
        //设置账户
        ((MysqlDataSource)dataSource).setUser("root");
        //设置密码
        ((MysqlDataSource)dataSource).setPassword("st730930");
        //
        Connection connection = dataSource.getConnection();
        //插入sql语句
        String sql = "insert into student value(101,'张三')";
        String sql2 = "insert into student values(102,'李四'),(103,'王五'),(104,'赵六')";
        //实例化1个preparedStatement对象
        PreparedStatement statement = connection.prepareStatement(sql);
        PreparedStatement statement1 = connection.prepareStatement(sql2);

        int ret = statement.executeUpdate();
        System.out.println(ret);//输出创建好了几个sql语句

        int ret2 = statement1.executeUpdate();
        System.out.println(ret2);
        //释放必要的资源
        statement.close();
        connection.close();*/
        MysqlDataSource dataSource = new MysqlDataSource();
        dataSource.setUrl("jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&useSSL=false");
        dataSource.setUser("root");
        dataSource.setPassword("st730930");
        Connection connection = dataSource.getConnection();

        String sql1 ="insert into student value(101,'张三')";
        String sql2 ="insert into student values(102,'李四'),(103,'王五'),(104,'赵六')";
        PreparedStatement statement1 = connection.prepareStatement(sql1);
        PreparedStatement statement2 = connection.prepareStatement(sql2);

        int ret1 = statement1.executeUpdate();
        System.out.println(ret1);
        int ret2 = statement2.executeUpdate();
        System.out.println(ret2);
        connection.close();
        statement1.close();
        statement2.close();
    }
}
